import goodsInfoModal from '../../../goodsInfoModal'
import detailsModal from '../../../detailsModal'
import CIQModel from '../../../CIQModel'
import CIQgoodsSpecModal from '../../../CIQgoodsSpecModal.vue'
import goodsAttributeModal from '../../../goodsAttributeModal'
import goodsAptitudeModal from '../../../goodsAptitudeModal'
import dangerGoodsInfoModal from '../../../dangerGoodsInfoModal'

export default {
    components: {
        goodsInfoModal,
        detailsModal,
        CIQModel,
        CIQgoodsSpecModal,
        goodsAttributeModal,
        goodsAptitudeModal,
        dangerGoodsInfoModal
    },
    data () {
        return {
            modalParams: {
                goodsInfoParams: {},
                goodsInfoShow: false,

                CIQModelParams: {},
                CIQModelShow: false,

                CIQgoodsSpecParams: {},
                CIQgoodsSpecShow: false,

                goodsAttributeParams: {},
                goodsAttributeShow: false,

                goodsAptitudeParams: {},
                goodsAptitudeShow: false,

                dangerGoodsInfoShow: false,
                dangerGoodsInfoParams: {}
            }
        }
    },
    methods: {
        // 打开商品选择弹窗
        openGoodsModal (event) {
            event && event.stopPropagation()
            const code = this.form.codeTs
            if (code && code.length > 3) {
                this.modalParams.goodsInfoParams = Object.freeze({
                    code
                })
                this.modalParams.goodsInfoShow = true
            } else {
                this.$Message.warning('请至少输入四位商品编码！')
            }
        },
        // 打开商品规格型号 弹窗
        openGsmModal (data) {
            const code = data.codeTs
            if (code && code.length === 10) {
                const {
                    goodsModel,
                    ieFlag,
                    disabled
                } = data
                this.$refs.detailsModalRef.init(
                    code,
                    goodsModel,
                    ieFlag, // E 表示出口||出境  I 表示进口||进境
                    disabled
                )
            } else {
                this.$Message.warning('请先填写10位商品编号！')
            }
        },

        // 检验检疫弹窗
        openCIQmodel () {
            let codeTs = this.form.codeTs
            if (codeTs && codeTs.length === 10) {
                this.modalParams.CIQModelParams = Object.freeze({
                    codeTs,
                    ciqName: this.form.ciqName,
                    disabled: this.disabled
                })
                this.modalParams.CIQModelShow = true
            } else {
                this.$Message.warning('请先填写10位商品编号！')
            }
        },
        // 保存 检疫检验名称以及code
        saveCIQ (data) {
            this.form.ciqName = data && data.ciqName || ''
            this.form.ciqCode = data && data.ciqCode || ''
            this.focusElement('gqty')
        },

        // 打开检验检疫货物规格弹窗
        openGoodsSpec () {
            this.modalParams.CIQgoodsSpecParams = Object.freeze({
                goodsSpec: this.form.goodsSpec,
                disabled: this.disabled
            })
            this.modalParams.CIQgoodsSpecShow = true
        },
        // 保存检验检疫货物规格
        saveGoodsSpec (str) {
            this.form.goodsSpec = str
            setTimeout(() => {
                this.openGoodsAttr()
            }, 200)
        },

        // 打开货物属性弹窗
        openGoodsAttr () {
            this.modalParams.goodsAttributeParams = Object.freeze({
                goodsAttr: this.form.goodsAttr,
                disabled: this.disabled
            })
            this.modalParams.goodsAttributeShow = true
        },

        // 保存货物属性
        saveGoodsAttr (res) {
            this.form.goodsAttr = res.codes
            this.form.goodsAttrCHN = res.names
            this.focusElement('purpose')
        },

        // 打开产品资质弹窗
        openGoodsAptitude (data) {
            this.modalParams.goodsAptitudeParams = Object.freeze(data)
            this.modalParams.goodsAptitudeShow = true
        },
        // 保存产品资质
        saveGoodsAptitude (list) {
            this.form.customsGoodsLimitNewVos = list.slice()
        },

        // 打开危险获取信息弹窗
        openDangerInfo () {
            let data = Object.freeze({
                noDangFlag: this.form.noDangFlag,
                unCode: this.form.unCode,
                dangName: this.form.dangName,
                dangPackType: this.form.dangPackType,
                dangPackSpec: this.form.dangPackSpec
            })
            this.modalParams.dangerGoodsInfoParams = {
                data,
                editORshow: this.editORshow
            }
            this.modalParams.dangerGoodsInfoShow = true
        },
        // 保存危险获取信息
        saveDangerData (data) {
            for (let i in data) {
                this.form[i] = data[i]
            }
        }
    }
}
